package cn.han.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Test4 {
    public static void main(String[] args) throws Exception {
        Connection c = Test4.getConnection();
        Statement statement = c.createStatement();
        ResultSet resultSet = statement.executeQuery("select * from dept;");
        while (resultSet.next()){
            int a = resultSet.getInt(1);
            System.out.println(a);
        }
        resultSet.close();
        statement.close();
        c.close();

    }
    static public Connection getConnection()throws Exception{
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/cgb2018";
        Connection connection = DriverManager.getConnection(url,"root","root");
        return connection;
    }
}
